package com.leetcode;

import org.junit.Test;

import java.util.stream.IntStream;

/**
 * Created by Z-hong on 2022/12/21.
 */

public class LeetCode1753 {
    public int maximumScore(int a, int b, int c) {
        int r;
        if(a>b){
            r=a;a=b;b=r;
        }
        if(b>c){
            r=c;c=b;b=r;
        }
        if(a>b){
            r=a;a=b;b=r;
        }

        if((a+b)==c){
            return c;
        }else if((a+b)>c){
            if(a==b){
                if(c%2==1){
                    return c+(a-c/2-1);
                }else return c+a-c/2;
            }else {
                int f=Math.min(a,b);
                int out=0;
                for(int i=0;i<=f;i++){
                    if (i>c)break;
                    out=Math.max(out,Math.min(a-i,b-c+i)+c);
                }
                return out;
            }
        }else return a+b;
    }

    public int maximumScore1(int a, int b, int c) {
        int mx = Math.max(a, Math.max(b,c));
        int sum = IntStream.of(a,b,c).sum();
        if(mx>sum/2) return sum - mx;
        else return sum/2;


    }

    @Test
    public void test(){
        System.out.println(maximumScore(21, 2, 18));
    }
}
